package logic

import (
	"context"
	"zhihu/models/mysql"

	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AnswerListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAnswerListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AnswerListLogic {
	return &AnswerListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AnswerListLogic) AnswerList(in *zhihurpc.AnswerListRequest) (*zhihurpc.AnswerListResponse, error) {
	// todo: add your logic here and delete this line
	var findanswe []mysql.Answer
	mysql.DB.Debug().Find(&findanswe)

	var answeList []*zhihurpc.AnswerList

	for _, answer := range findanswe {
		list := zhihurpc.AnswerList{
			Speak:     answer.Speak,
			ProblemId: int64(answer.ProblemId),
			UserId:    int64(answer.UserId),
		}
		answeList = append(answeList, &list)
	}

	return &zhihurpc.AnswerListResponse{
		List: answeList,
	}, nil
}
